home *** CD-ROM | disk | FTP | other *** search
/ World of Sound / World of Sound.iso / utils / miditools / kawaied / src / envdisplay.c < prev    next >
C/C++ Source or Header  |  1992-10-25  |  13KB  |  548 lines

  1. #include "inc.h"
  2. #include "defs.h"
  3. #include "req_manx_5.c"
  4. #include <exec/memory.h>
  5.  
  6. extern int envlevel[4];
  7. extern int envdelay[4];
  8. extern int envattack[4];
  9. extern int envdecay[4];
  10. extern int envsustain[4];
  11. extern int envrelease[4];
  12. extern int mute[4];
  13. extern int sources;
  14.  
  15. int oldenvlevel[4];
  16. int oldenvdelay[4];
  17. int oldenvattack[4];
  18. int oldenvdecay[4];
  19. int oldenvsustain[4];
  20. int oldenvrelease[4];
  21.  
  22. int delx[4],dely[4];
  23. int attx[4],atty[4];
  24. int decx[4],decy[4];
  25. int relx[4],rely[4];
  26. int x1[4],y1[4],x2[4],y2[4],x3[4],y3[4],x4[4],y4[4],x5[4],y5[4];
  27. int X1[4],Y1[4],X2[4],Y2[4],X3[4],Y3[4],X4[4],Y4[4],X5[4],Y5[4];
  28.  
  29. struct Window     *WIN;
  30. struct RastPort *RP;
  31.  
  32. void EnvDisplay(void);
  33. void EnvEdit(int nr);
  34. void BigEnvDisplay(int nr);
  35. void SaveCoord(void);
  36.  
  37. /**********************************************************************************/
  38. /***                                                                            ***/
  39. /**********************************************************************************/
  40.  
  41. void EnvDisplay(void)
  42. {
  43.     int i;
  44.     int x1[4],y1[4],x2[4],y2[4],x3[4],y3[4],x4[4],y4[4],x5[4],y5[4];
  45.     BOOL f;
  46.     
  47.     f=4;
  48.     for (i=0;i<=2*(sources+1)-1;i++)
  49.     {
  50.         if(oldenvlevel[i]    !=    envlevel[i]  )     f=i;
  51.         if(oldenvdelay[i]    !=    envdelay[i]  )    f=i;
  52.         if(oldenvattack[i]    !=    envattack[i] )    f=i;
  53.         if(oldenvdecay[i]    !=    envdecay[i]  )    f=i;
  54.         if(oldenvsustain[i]    !=    envsustain[i])    f=i;
  55.         if(oldenvrelease[i]    !=    envrelease[i])    f=i;
  56.     }
  57.  
  58.     if (f!=4)
  59.     {
  60.         for (i=2*(sources+1)-1;i>=0;i--)
  61.         {        
  62.             x1[i]=260+10*(3-i);                    y1[i]=0;
  63.             x2[i]=x1[i]+envdelay[i]*35/100;        y2[i]=0;
  64.             x3[i]=x2[i]+envattack[i]*40/100;    y3[i]=envlevel[i]*35/100;
  65.             x4[i]=x3[i]+envdecay[i]*40/100;      y4[i]=envsustain[i]*35/100*envlevel[i]/100;
  66.             x5[i]=x4[i]+envrelease[i]*40/100;     y5[i]=0;
  67.         }
  68.  
  69.         SetAPen(rp,0);
  70.         RectFill(rp,261,21,452,74);
  71.         SetAPen(rp,1);
  72.  
  73.         for (i=2*(sources+1)-1;i>=0;i--)
  74.         {    
  75.             int ii=74-5*i;
  76.         
  77.             if (mute[i]!=0) goto Ende;
  78.  
  79.             SetAPen(rp,2);
  80.             AreaMove(rp,x1[i]    ,ii-y1[i]);
  81.             AreaDraw(rp,x2[i]    ,ii-y2[i]);
  82.             AreaDraw(rp,x3[i]    ,ii-y3[i]);
  83.             AreaDraw(rp,x4[i]    ,ii-y4[i]);
  84.             AreaDraw(rp,x5[i]    ,ii-y5[i]);
  85.             AreaEnd(rp);
  86.             SetAPen(rp,1);
  87.  
  88.             Line(win,x1[i]    ,ii-y1[i]    ,x2[i]    ,ii-y2[i]);
  89.             Line(win,x2[i]    ,ii-y2[i]    ,x3[i]    ,ii-y3[i]);
  90.             Line(win,x3[i]    ,ii-y3[i]    ,x4[i]    ,ii-y4[i]);
  91.             Line(win,x4[i]    ,ii-y4[i]    ,x5[i]    ,ii-y5[i]);
  92.             Line(win,x1[i]    ,ii-y1[i]    ,x5[i]    ,ii-y5[i]);
  93.         
  94.             Ende: ;        
  95.         }
  96.     }
  97.     Line(win,261,59,291,74);
  98.  
  99.     for (i=0;i<=2*(sources+1)-1;i++)
  100.     {
  101.         oldenvlevel[i]        = envlevel[i];
  102.         oldenvdelay[i]        = envdelay[i];
  103.         oldenvattack[i]        = envattack[i];
  104.         oldenvdecay[i]        = envdecay[i];
  105.         oldenvsustain[i]    = envsustain[i];
  106.         oldenvrelease[i]    = envrelease[i];
  107.     }
  108. }
  109.  
  110. /**********************************************************************************/
  111. /***                                                                            ***/
  112. /**********************************************************************************/
  113.  
  114. void EnvEdit(int nr)
  115. {
  116.     FILE *fp,*fopen();
  117.     char string[255];
  118.     static struct NewWindow nw;
  119.     struct Gadget *gad;
  120.     int id,i,ii;
  121.     int x,y,xold,yold;
  122.     char *p=(char *)0xbfe001;
  123.  
  124.     int oldenvlevel[4];
  125.     int oldenvdelay[4];
  126.     int oldenvattack[4];
  127.     int oldenvdecay[4];
  128.     int oldenvsustain[4];
  129.     int oldenvrelease[4];
  130.  
  131.     for (i=0;i<=3;i++)
  132.     {
  133.         oldenvlevel[i]=envlevel[i];
  134.         oldenvdelay[i]=envdelay[i];
  135.         oldenvattack[i]=envattack[i];
  136.         oldenvdecay[i]=envdecay[i];
  137.         oldenvsustain[i]=envsustain[i];
  138.         oldenvrelease[i]=envrelease[i];
  139.     }    
  140.  
  141.     nw.Width = 620;
  142.     nw.Height = 110+100*sources;
  143.     nw.DetailPen = 0;
  144.     nw.BlockPen = 1;
  145.     nw.Title ="KAWAI K1-II Librarian...Graphic Envelope Editor";
  146.     nw.Flags=RMBTRAP|ACTIVATE|REPORTMOUSE|SMART_REFRESH|WINDOWDRAG|WINDOWCLOSE|(SCREEN==0 ? WINDOWDEPTH : NULL);
  147.     nw.IDCMPFlags = GADGETUP|GADGETDOWN|CLOSEWINDOW|MOUSEMOVE;
  148.     nw.Type = (SCREEN != 0 ? CUSTOMSCREEN : WBENCHSCREEN);
  149.     nw.CheckMark = NULL;
  150.     nw.NextGadget=NULL;
  151.     nw.Screen = (SCREEN != 0 ? scr : NULL);
  152.     nw.BitMap = NULL;
  153.     nw.MinWidth = 0;
  154.     nw.MinHeight = 0;
  155.     nw.MaxWidth = 0;
  156.     nw.MaxHeight = 0;    
  157.     nw.LeftEdge = 10;
  158.     nw.TopEdge = 10;
  159.  
  160.     WIN=(struct Window *) OpenWindow(&nw);
  161.     if (WIN==NULL) Error("Can't open EnvEdit-window");
  162.     RP=WIN->RPort;
  163.     SetFont(RP,textfont);
  164.  
  165.     /* Setup window */
  166.     SetAPen(RP,1);
  167.  
  168.     Print(WIN,13,103+100*sources,"Undo");
  169.     MakeDBox(WIN,10,95+100*sources,50,105+100*sources);
  170.  
  171.     MakeBox(WIN,100,20,300,90);     MakeBox(WIN,400,20,600,90); 
  172.     if (sources==1)
  173.     {
  174.         MakeBox(WIN,100,120,300,190);     MakeBox(WIN,400,120,600,190); 
  175.     }
  176.  
  177.     for (i=0;i<=2*(sources+1)-1+(sources==0 ? 1 : 0);i++) BigEnvDisplay(i);    
  178.     
  179.  
  180. Loop: WIN->IDCMPFlags = CLOSEWINDOW|MOUSEBUTTONS|MOUSEMOVE;
  181.     WaitPort(WIN->UserPort);
  182.  
  183.     while(mesg = (struct IntuiMessage *) GetMsg(WIN->UserPort))
  184.     {
  185.         class=mesg->Class; 
  186.         code=mesg->Code;
  187.         x=mesg->MouseX;
  188.         y=mesg->MouseY;
  189.         if (class==GADGETUP || class==GADGETDOWN)
  190.         {
  191.             gad=mesg->IAddress;
  192.             id=gad->GadgetID;
  193.         }
  194.         ReplyMsg((struct Message *)mesg);
  195.         WIN->IDCMPFlags= NULL;;
  196.     
  197.         for (i=0;i<=3;i++)
  198.         {
  199.             X1[i]=x1[i];     Y1[i]=y1[i];
  200.             X2[i]=x2[i];    Y2[i]=y2[i];
  201.             X3[i]=x3[i];    Y3[i]=y3[i];
  202.             X4[i]=x4[i];    Y4[i]=y4[i];
  203.             X5[i]=x5[i];    Y5[i]=y5[i];
  204.         }
  205.     
  206.         if (class == CLOSEWINDOW)
  207.         {
  208.             CloseWindow(WIN);
  209.             return;
  210.         }
  211.  
  212.         if (class == MOUSEBUTTONS)
  213.         {    
  214.             if (x>=10 && x<=50 && y>=95+100*sources && y<=105+100*sources)    /* Undo */
  215.             {
  216.                 if (MyReq("Are you shure ?"," Yes ","Oh no"))
  217.                 {
  218.                     for (i=0;i<=3;i++)
  219.                     {
  220.                         envlevel[i]        =oldenvlevel[i];
  221.                         envdelay[i]        =oldenvdelay[i];
  222.                         envattack[i]    =oldenvattack[i];
  223.                         envdecay[i]        =oldenvdecay[i];
  224.                         envsustain[i]    =oldenvsustain[i];
  225.                         envrelease[i]    =oldenvrelease[i];
  226.                         BigEnvDisplay(i);
  227.                     }
  228.                     TransmitSingleSound(nr);
  229.                 }    
  230.             }    
  231.         }
  232.  
  233.         if (class== MOUSEMOVE && *p != -4)
  234.         {
  235.  
  236.             if ((i=CheckDelay(x,y))>=0)
  237.             {
  238.                 int val;
  239.     
  240.                 if (i==1 || i==3) x-=400;
  241.                             else  x-=100;
  242.     
  243.                 if (i==2 || i==3) y-=120;
  244.                             else  y-=30;                
  245.     
  246.                 while(*p != -4)
  247.                 {    
  248.                     SaveCoord();
  249.                     xold=val;
  250.                     x=WIN->MouseX;
  251.                     y=WIN->MouseY;
  252.                     
  253.                     if (i==1 || i==3) x-=400;
  254.                                 else  x-=100;
  255.     
  256.                     if (i==2 || i==3) y-=140;    
  257.                                 else  y-=30;                
  258.     
  259.                     val=2*x;            
  260.                     if (val>=100) val=100;
  261.                     if (val<=0)  val=0;
  262.                     envdelay[i]=val;
  263.                     if (xold != val)
  264.                     {
  265.                          BigEnvDisplay(i);
  266.                         SingleParameterSend(42,i,envdelay[i]);
  267.                     }
  268.                 } 
  269.             }        
  270.     
  271.             if ((i=CheckAttack(x,y))>=0)
  272.             {
  273.                 int valx,valy;
  274.     
  275.                 if (i==1 || i==3) x-=400;
  276.                             else  x-=100;
  277.     
  278.                 if (i==2 || i==3) y-=130;
  279.                             else  y-=30;                
  280.     
  281.                 while(*p != -4)
  282.                 {    
  283.                     SaveCoord();
  284.                     xold=valx;
  285.                     yold=valy;
  286.                     x=WIN->MouseX;
  287.                     y=WIN->MouseY;
  288.                     
  289.                     if (i==1 || i==3) x-=400;
  290.                                 else  x-=100;
  291.                     x=x-envdelay[i]/2;
  292.                     
  293.                     if (i==2 || i==3) y-=130;    
  294.                                 else  y-=30;                
  295.         
  296.                     valx=x*2;    
  297.                     valy=100-y*100/60;        
  298.                     if (valx>=100) valx=100;
  299.                     if (valx<=0)  valx=0;
  300.                     if (valy>=100) valy=100;
  301.                     if (valy<=0)  valy=0;
  302.                     envattack[i]=valx;
  303.                     envlevel[i]=valy;
  304.                     if (xold != valx || yold !=valy)
  305.                     {
  306.                         BigEnvDisplay(i);
  307.                         SingleParameterSend(43,i,envattack[i]);
  308.                         SingleParameterSend(41,i,envlevel[i]);
  309.                     }
  310.                 } 
  311.             }        
  312.     
  313.             if ((i=CheckDecay(x,y))>=0)
  314.             {
  315.                 int valx,valy;
  316.     
  317.                 if (i==1 || i==3) x-=400;
  318.                             else  x-=100;
  319.     
  320.                 if (i==2 || i==3) y-=130;
  321.                             else  y-=30;                
  322.     
  323.                 while(*p != -4)
  324.                 {    
  325.                     SaveCoord();
  326.                     xold=valx;
  327.                     yold=valy;
  328.                     x=WIN->MouseX;
  329.                     y=WIN->MouseY;
  330.                     
  331.                     if (i==1 || i==3) x-=400;
  332.                                 else  x-=100;
  333.                     x=x-envdelay[i]/2-envattack[i]/2;
  334.                     
  335.                     if (i==2 || i==3) y-=130;    
  336.                                 else  y-=30;                
  337.     
  338.                     valx=x*2;
  339.                     valy=(envlevel[i] != 0 ? (100-y*100/60)*100/envlevel[i] : 0);    
  340.                     if (valx>=100) valx=100;
  341.                     if (valx<=0)  valx=0;
  342.                     if (valy>=100) valy=100;
  343.                     if (valy<=0)  valy=0;
  344.                     envdecay[i]=valx;
  345.                     envsustain[i]=valy;
  346.                     if (xold != valx || yold !=valy) 
  347.                     {
  348.                         BigEnvDisplay(i);
  349.                         SingleParameterSend(44,i,envdecay[i]);
  350.                         SingleParameterSend(45,i,envsustain[i]);
  351.                     }
  352.                 }
  353.             }        
  354.     
  355.             if ((i=CheckRelease(x,y))>=0)
  356.             {
  357.                 int valx,valy;
  358.     
  359.                 if (i==1 || i==3) x-=400;
  360.                             else  x-=100;
  361.     
  362.                 if (i==2 || i==3) y-=130;
  363.                             else  y-=30;                
  364.     
  365.                 while(*p != -4)
  366.                 {    
  367.                     SaveCoord();
  368.                     xold=valx;
  369.                     yold=valy;
  370.                     x=WIN->MouseX;
  371.                     y=WIN->MouseY;
  372.                     
  373.                     if (i==1 || i==3) x-=400;
  374.                                 else  x-=100;
  375.                     x=x-envdelay[i]/2-envattack[i]/2-envdecay[i]/2;
  376.                     
  377.                     if (i==2 || i==3) y-=130;    
  378.                                 else  y-=30;                
  379.     
  380.                     valx=x*2;
  381.                     if (valx>=100) valx=100;
  382.                     if (valx<=0)  valx=0;
  383.                     envrelease[i]=valx;
  384.                     if (xold != valx || yold !=valy)
  385.                     { 
  386.                         BigEnvDisplay(i);
  387.                         SingleParameterSend(46,i,envrelease[i]);
  388.                     }
  389.                 }
  390.             }        
  391.         }
  392.     }
  393. goto Loop;
  394.  
  395. Loop1:    CloseWindow(WIN);
  396. }
  397.  
  398. /**********************************************************************************/
  399. /***                                                                            ***/
  400. /**********************************************************************************/
  401.  
  402. int CheckDelay(int x, int y)
  403. {
  404.     int i;
  405.  
  406.     for (i=0;i<=3;i++)
  407.     {
  408.         if (x<=delx[i]+0 && x>=delx[i]-7 && y<dely[i]+3 && y>dely[i]-3) return(i);
  409.     }
  410.     return(-1);
  411. }
  412.  
  413. /**********************************************************************************/
  414. /***                                                                            ***/
  415. /**********************************************************************************/
  416.  
  417. int CheckAttack(int x, int y)
  418. {
  419.     int i;
  420.  
  421.     for (i=0;i<=3;i++)
  422.     {
  423.         if (x<=attx[i]+2 && x>=attx[i]-5 && y<atty[i]+3 && y>atty[i]-3) return(i);
  424.     }
  425.     return(-1);
  426. }
  427.  
  428. /**********************************************************************************/
  429. /***                                                                            ***/
  430. /**********************************************************************************/
  431.  
  432. int CheckDecay(int x, int y)
  433. {
  434.     int i;
  435.  
  436.     for (i=0;i<=3;i++)
  437.     {
  438.         if (x<=decx[i]+5 && x>=decx[i]-1 && y<decy[i]+3 && y>decy[i]-3) return(i);
  439.     }
  440.     return(-1);
  441. }
  442.  
  443. /**********************************************************************************/
  444. /***                                                                            ***/
  445. /**********************************************************************************/
  446.  
  447. int CheckRelease(int x, int y)
  448. {
  449.     int i;
  450.  
  451.     for (i=0;i<=3;i++)
  452.     {
  453.         if (x<=relx[i]+7 && x>=relx[i]-0 && y<rely[i]+3 && y>rely[i]-3) return(i);
  454.     }
  455.     return(-1);
  456. }
  457.  
  458. /**********************************************************************************/
  459. /***                                                                            ***/
  460. /**********************************************************************************/
  461.  
  462. void BigEnvDisplay(int i)
  463. {
  464.     char string[255];
  465.     int ii;
  466.         
  467.     SetAPen(RP,0);
  468.     SetBPen(RP,0);
  469.     Line(WIN,X1[i]    ,Y1[i]    ,X2[i]    ,Y2[i]);
  470.     Line(WIN,X2[i]    ,Y2[i]    ,X3[i]    ,Y3[i]);
  471.     Line(WIN,X3[i]    ,Y3[i]    ,X4[i]    ,Y4[i]);
  472.     Line(WIN,X4[i]    ,Y4[i]    ,X5[i]    ,Y5[i]);
  473.  
  474.     MakeBox(WIN,X2[i]-7,Y2[i]-3,X2[i]+0,Y2[i]+3);
  475.     MakeBox(WIN,X3[i]-5,Y3[i]-3,X3[i]+2,Y3[i]+3);
  476.     MakeBox(WIN,X4[i]-1,Y4[i]-3,X4[i]+5,Y4[i]+3);
  477.     MakeBox(WIN,X5[i]-0,Y5[i]-3,X5[i]+7,Y5[i]+3);
  478.     SetAPen(RP,1);
  479.  
  480.     SetAPen(RP,1);
  481.  
  482.     if (i==0) MakeBox(WIN,100,20,300,90);
  483.     if (i==1) MakeBox(WIN,400,20,600,90); 
  484.     if (i==2) MakeBox(WIN,100,120,300,190);
  485.     if (i==3) MakeBox(WIN,400,120,600,190); 
  486.     
  487.     ii=90+100*(i/2);
  488.  
  489.     x1[i]=300*(i%2)+100;                y1[i]=ii;
  490.     x2[i]=x1[i]+envdelay[i]*50/100;        y2[i]=ii;
  491.     x3[i]=x2[i]+envattack[i]*50/100;    y3[i]=ii-envlevel[i]*60/100;
  492.     x4[i]=x3[i]+envdecay[i]*50/100;        y4[i]=ii-envsustain[i]*60/100*envlevel[i]/100;
  493.     x5[i]=x4[i]+envrelease[i]*50/100;     y5[i]=ii;
  494.  
  495.     delx[i]=x2[i];    dely[i]=y2[i];
  496.     attx[i]=x3[i];    atty[i]=y3[i];
  497.     decx[i]=x4[i];    decy[i]=y4[i];
  498.     relx[i]=x5[i];    rely[i]=y5[i];
  499.  
  500.     Line(WIN,x1[i]    ,y1[i]    ,x2[i]    ,y2[i]);
  501.     Line(WIN,x2[i]    ,y2[i]    ,x3[i]    ,y3[i]);
  502.     Line(WIN,x3[i]    ,y3[i]    ,x4[i]    ,y4[i]);
  503.     Line(WIN,x4[i]    ,y4[i]    ,x5[i]    ,y5[i]);
  504.  
  505.     SetAPen(RP,2);
  506.     MakeBox(WIN,x2[i]-7,y2[i]-3,x2[i]+0,y2[i]+3);
  507.     MakeBox(WIN,x3[i]-5,y3[i]-3,x3[i]+2,y3[i]+3);
  508.     MakeBox(WIN,x4[i]-1,y4[i]-3,x4[i]+5,y4[i]+3);
  509.     MakeBox(WIN,x5[i]-0,y5[i]-3,x5[i]+7,y5[i]+3);
  510.  
  511.     sprintf(string,"Env #%d",i+1);
  512.     Print(WIN,175+300*(i%2),18+100*(i/2),string);
  513.  
  514.     sprintf(string,"Del: %3d",envdelay[i]);
  515.     ColPrint(WIN,10+300*(i%2),30+100*(i/2)-2,string);
  516.     sprintf(string,"Att: %3d",envattack[i]);
  517.     ColPrint(WIN,10+300*(i%2),40+100*(i/2)-2,string);
  518.     sprintf(string,"Dec: %3d",envdecay[i]);
  519.     ColPrint(WIN,10+300*(i%2),50+100*(i/2)-2,string);
  520.     sprintf(string,"Sus: %3d",envsustain[i]);
  521.     ColPrint(WIN,10+300*(i%2),60+100*(i/2)-2,string);
  522.     sprintf(string,"Rel: %3d",envrelease[i]);
  523.     ColPrint(WIN,10+300*(i%2),70+100*(i/2)-2,string);
  524.     sprintf(string,"Lev: %3d",envlevel[i]);
  525.     ColPrint(WIN,10+300*(i%2),80+100*(i/2)-2,string);
  526.     if (mute[i]==1)    ColPrint(WIN,10+300*(i%2),90+100*(i/2)-2,"OFF");
  527.     
  528.     SetAPen(RP,1);
  529. }
  530.  
  531. /**********************************************************************************/
  532. /***                                                                            ***/
  533. /**********************************************************************************/
  534.  
  535. void SaveCoord(void)
  536. {
  537.     int i;
  538.     
  539.     for (i=0;i<=3;i++)
  540.     {
  541.         X1[i]=x1[i];     Y1[i]=y1[i];
  542.         X2[i]=x2[i];    Y2[i]=y2[i];
  543.         X3[i]=x3[i];    Y3[i]=y3[i];
  544.         X4[i]=x4[i];    Y4[i]=y4[i];
  545.         X5[i]=x5[i];    Y5[i]=y5[i];
  546.     }
  547. }
  548.